<?php
//user.php

if(!isset($authorizedPage)) require('../error.php');

require('../recipie.php');


class User{
	private $userID;
	private $userRecipies = array();
	private $userName;
	
	public function __construct($uid){
		$this->userID = $uid;
	}
	
	public function fillVariables(){
		$query = mysql_query("SELECT id FROM recipie WHERE userid = '$this->userID'");
		
		while($row = mysql_fetch_row($query)){
			$this->userRecipies[] = $row[0];
		}
		
		$pageContent = file_get_contents('http://graph.facebook.com/' . $this->getUserID());
		$parsedJson  = json_decode($pageContent);
		$this->userName = $parsedJson->name;
		
		return $parsedJson->id;
	}
	
	public function getUserFacebookProfile(){
		return '<img src="http://graph.facebook.com/'.$this->getUserID().'/picture?type=normal&height=104" alt="'.$this->getUserName().' Profile Picture" />';
	}
	
	public function getUserID(){
		return $this->userID;
	}

	public function getUserName(){
		return $this->userName;
	}
	
	public function getUserRecipies(){
		return $this->userRecipies();
	}
	
	public function getUserRecipiesCount(){
		return count($this->userRecipies);
	}
	
	//**generateRecipieMarkUp
	//
	//Contain class used is 'userRecipieContain'
	//Recipie name class used is 'userRecipieName'
	public function generateRecipieMarkUp(){
		foreach($this->userRecipies as $value){
			$recipie = new Recipie($value);
			$recipie->fillVariables();
			echo '<div class="userRecipieContain">';
			echo '<span class="userRecipieName">';
			echo '<a href="view.php?rid='.$value.'">';
			echo $recipie->getRName();
			echo '</a>';
			echo '</span>';
			echo '</div>'."\n";
		}
	}
}

	
?>